import SecureLS from 'secure-ls';
import { defineStore } from 'pinia';

const ls = new SecureLS({
  encodingType: 'aes',
  isCompression: true,
  encryptionSecret: 'some-secret',
});

const useSecuredStore = defineStore('secured-store', {
  state: () => {
    return {
      count: 0,
    };
  },
  actions: {
    resetCount(toZero = true) {
      this.count = toZero ? 0 : 100;
    },
  },
  persist: {
    key: 'pinia-secured',
    storage: {
      getItem: key => ls.get(key),
      setItem: (key, value) => ls.set(key, value),
    },
  },
});

export { useSecuredStore };
